<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 用户邀请接口
 */
class UserInvite extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    public function getUserInviteList()
    {
        $user = $this->auth->getUser();
        $pageIndex = $this->request->post('pageIndex', 1);
        $pageSize = $this->request->post('pageSize', 10);
        $list = model('\app\admin\model\jy\UserInvite')
            ->with('user')
            ->where("invite_user_id", $user['id'])
            ->order('update_time desc')
            ->paginate($pageSize, false, ['page' => $pageIndex]);
        $newList = [];
        if ($list) {
            foreach ($list as $key => $l) {
                $newList[$key] = [
                    'avatar' => $l['user']['avatar'],
                    'phone'  => $l['user']['mobile'] ? substr_replace($l['user']['mobile'], '****', 3, 4) : $l['user']['mobile'],
                ];
            }
        }
        $result = array("total" => $list->total(), "rows" => $newList);
        $this->success('', $result);
    }

}